package com.zb.sannuo.maintenance.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zb.sannuo.common.domain.Menu;
import com.zb.sannuo.common.domain.Role;
import com.zb.sannuo.common.domain.search.PatientDrugstoreSearch;
import com.zb.sannuo.common.result.Result;
import com.zb.sannuo.common.result.ResultCode;
import com.zb.sannuo.maintenance.service.RolePermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

@RestController
@RequestMapping("/rolePermission")
@CrossOrigin
@Api(tags = "分配角色权限管理模块", description = "对分配角色权限进行CRUD操作")
public class RolePermissionController {
    @Resource
    private RolePermissionService rolePermissionService;

    @RequestMapping(value = "list",method = RequestMethod.GET)
    @ApiOperation(value = "角色权限分页查询",tags = "分页查询角色权限信息")
    public Result queryRolePermission(Integer page, Integer limit)throws Exception{

        Page page1 = rolePermissionService.selectListRolePermission(page, limit);
        System.out.println(page1.getTotal());
        return Result.ok(ResultCode.SUCCESS,page1.getTotal(),page1.getRecords());
    }

    @RequestMapping(value = "add",method = RequestMethod.POST)
    @ApiOperation(value = "角色权限增加功能",notes = "角色权限增加功能")
    public Result addRolePermission(Role role)throws Exception{
        int i = rolePermissionService.addPermission(role);
        return Result.ok(ResultCode.SUCCESS,i);
    }

    @RequestMapping(value = "update",method = RequestMethod.POST)
    @ApiOperation(value = "修改功能",notes = "修改功能")
    public Result updatePermission(Role role)throws Exception{
        int i = rolePermissionService.updatePermission(role);
        return Result.ok(ResultCode.SUCCESS,i);
    }
}
